package com.hsbc.manager.service.impl;


import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.hsbc.entity.Admin;
import com.hsbc.manager.dao.AdminRepository;
import com.hsbc.manager.service.AdminService;

@Service
public class AdminServiceImpl implements AdminService {

	@Autowired
	private AdminRepository adminRepository;
	
	@Override
	public Admin findAdminByUsername(String username) {
		return adminRepository.findByUsername(username);
	}

	@Override
	@Transactional
	public void addAdmin() throws Exception{
		Admin admin = new Admin();
		admin.setPassword("123");
		admin.setRealname("test");
		admin.setSalt("123");
		admin.setState((short) 1);
		admin.setUsername("test");
		adminRepository.saveAndFlush(admin);
		try {
			System.out.println("阻塞开始");
			Thread.sleep(10000);
			System.out.println("阻塞结束");
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		throw new RuntimeException("取消新增");
	}

	@Override
	@Transactional
	public void addAdmin1() {
		Admin admin = new Admin();
		admin.setPassword("1234");
		admin.setRealname("test1");
		admin.setSalt("1234");
		admin.setState((short) 1);
		admin.setUsername("test1");
		adminRepository.saveAndFlush(admin);
	}

//	@Override
//	public List<Admin1> findAdminInfo() {
//		List<Object[]> adminArr = adminRepository.findAdminInfo();
//		List<Admin1> adminList = new ArrayList<Admin1>();
//		Class<Admin1> clazz;
//		try {
//			clazz = (Class<Admin1>) Class.forName("com.hsbc.entity.Admin1");
//			adminList = EntityUtils.castEntity(adminArr, clazz, new Admin1());
//		} catch (ClassNotFoundException e) {
//			e.printStackTrace();
//		}
//		return adminList;
//	}

}
